﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pages_Periodo : System.Web.UI.UserControl
{
    public event EventHandler GoUp;
    public event EventHandler GoDown;
    public string Valor
    {
        get { return txtAnno.Text + txtMes.Text; }
    }
    public int Anno
    {
        get { return int.Parse(txtAnno.Text); }
        set { txtAnno.Text = value.ToString(); }
    }
    public int Mes
    {
        get { return int.Parse(txtMes.Text); }
        set { txtMes.Text = value.ToString("00"); }
    }
    public string Etiqueta
    {
        get { return lblTitulo.Text; }
        set { lblTitulo.Text = value; }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void imgArriba_Click(object sender, ImageClickEventArgs e)
    {
        actualizarTexto(true);
        if(GoUp != null)
            GoUp.Invoke(this, new EventArgs());

    }
    public void imgAbajo_Click(object sender, ImageClickEventArgs e)
    {
        actualizarTexto(false);
        if (GoDown!= null)
            GoDown.Invoke(this, new EventArgs());
    }

    private void actualizarTexto(bool pIncrementa)
    {
        int tAnno = Anno;
        int tMes = Mes;
        if (pIncrementa)
        {
            if (tMes == 12)
            {
                tMes = 1;
                tAnno += 1;
            }
            else
            {
                tMes += 1;
            }
        }
        else
        {
            if (tMes == 1)
            {
                tMes = 12;
                tAnno -= 1;
            }
            else
            {
                tMes -= 1;
            }
        }
        Anno = tAnno;
        Mes = tMes;
    }
}
